home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 626-637 / disk_632 / printfiles / source / prf_main.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  9KB  |  339 lines

  1.  
  2. /* prf_main.c */
  3. /* V1.1 9-3-92 */
  4.  
  5. #include "prf.h"
  6.  
  7. /* ------------------------------------------------------------------- */
  8. /*      for cback.o startup                                            */
  9. /* ------------------------------------------------------------------- */
  10.  
  11. long                      _stack        = 4000;
  12. char                      *_procname    = "*PrintFiles V1.1*";
  13. long                      priority      = 0;
  14. long                      _BackGroundIO = 0;
  15. extern BPTR               _Backstdout;
  16.  
  17. /* ----------------------------------------------------------------- */
  18.  
  19. void CheckCmdLine(struct prf_info *,int,union wbstart);
  20. void SetSTFlags(struct prf_info *,UBYTE *);
  21.  
  22.  
  23. struct IntuitionBase *IntuitionBase;
  24. struct Library       *WorkbenchBase;
  25. struct Library       *GadToolsBase;
  26. struct Library       *AslBase;
  27. struct Library       *IconBase;
  28. struct RxsLib        *RexxSysBase;
  29. struct GfxBase       *GfxBase;
  30.  
  31. void  main(int argc ,union wbstart argv)
  32. {
  33.  struct prf_info *info;
  34.  long end = (long)FALSE;
  35.  if(info = (struct prf_info *)calloc(1,sizeof(struct prf_info)))
  36.  {
  37.   if(OpenLibs(info))
  38.   {
  39.    if(OpenApp(info))
  40.    {
  41.     CheckCmdLine(info,argc,argv);
  42.     SetPrfSignals(info);
  43.     if(info->flags & FLAG_OPENWINDOW)
  44.     {
  45.      info->flags ^= FLAG_OPENWINDOW;
  46.      ChangeApp(info);
  47.     }
  48.     if(info->flags & FLAG_IMMEDIATE)
  49.     {
  50.      info->flags ^= FLAG_IMMEDIATE;
  51.      PrintQueue(info);
  52.     }
  53.     while(!end)
  54.     {
  55.      SetPrfSignals(info);
  56.      Wait(info->signals);
  57.      if(DoCommand(info,HandleMsgs(info)) == CMD_QUIT) end = (long)TRUE;
  58.     }
  59.     CloseApp(info);
  60.    }
  61.   }
  62.   CloseLibs(info);
  63.  }
  64.  exit(0);
  65. }
  66.  
  67. long  OpenLibs(struct prf_info *info)
  68. {
  69.  if(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",SYSTEM_VERSION))
  70.  {
  71.   if(WorkbenchBase = OpenLibrary("workbench.library",SYSTEM_VERSION))
  72.   {
  73.    if(AslBase = OpenLibrary("asl.library",SYSTEM_VERSION))
  74.    {
  75.     if(GadToolsBase = OpenLibrary("gadtools.library",SYSTEM_VERSION))
  76.     {
  77.      if(IconBase = OpenLibrary("icon.library",SYSTEM_VERSION))
  78.      {
  79.       if(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",SYSTEM_VERSION))
  80.       {
  81.        if(info->PubScr = LockPubScreen( "Workbench" ))
  82.        {
  83.         info->BarHeight = (ULONG)((long)(info->PubScr->BarHeight));
  84.         PwdTags[3].ti_Data    += info->BarHeight ;
  85.         SwdTags[3].ti_Data    += info->BarHeight ;
  86.         if(info->VisualInfo = GetVisualInfo(info->PubScr,TAG_DONE ))
  87.         {
  88.          NewList(&info->FileList);
  89.          AttemptOpenRexx(info);
  90.          Prf_Reset(info);
  91.          return ((long)TRUE);
  92.         }
  93.        }
  94.       }
  95.      }
  96.     }
  97.    }
  98.   }
  99.  }
  100.  return ((long)FALSE);
  101.  
  102. }
  103.  
  104. void  CloseLibs(struct prf_info *info)
  105. {
  106.  struct Node *n;
  107.  if(info)
  108.  {
  109.   CloseRexx(info);
  110.   if(info->Swd)CloseSwd(info);
  111.   if(info->Pwd)ClosePwd(info);
  112.   if(info->VisualInfo) FreeVisualInfo(info->VisualInfo);
  113.   if(info->PubScr)UnlockPubScreen(0L,info->PubScr);
  114.   while(n = (struct Node *)RemHead(&info->FileList))free((struct FileNameNode *)n);
  115.   free(info);
  116.  }
  117.  if (GfxBase)         CloseLibrary((struct Library *)GfxBase);
  118.  if (IconBase)        CloseLibrary(IconBase);
  119.  if (GadToolsBase)    CloseLibrary(GadToolsBase);
  120.  if (AslBase)         CloseLibrary(AslBase);
  121.  if (WorkbenchBase)   CloseLibrary(WorkbenchBase);
  122.  if (IntuitionBase)   CloseLibrary((struct Library *)IntuitionBase);
  123. }
  124.  
  125. void  Prf_Reset(struct prf_info *info)
  126. {
  127.  struct Node *n;
  128.  while(n = (struct Node *)RemHead(&info->FileList))free((struct FileNameNode *)n);
  129.  info->Lines   = DEFAULT_LINES;
  130.  info->Rmargin = DEFAULT_RMARGIN;
  131.  info->Lmargin = DEFAULT_LMARGIN;
  132.  info->Lines   = DEFAULT_LINES;
  133.  info->flags   = DEFAULT_FLAGS;
  134.  info->Columns = DEFAULT_RMARGIN - DEFAULT_LMARGIN;
  135.  strcpy(info->Headline, DEFAULT_HEADLINE);
  136.  strcpy(info->Footline, DEFAULT_FOOTLINE);
  137.  RefreshPwd(info);
  138.  RefreshSwd(info);
  139. }
  140.  
  141. void SetPrfSignals(struct prf_info *info)
  142. {
  143.  info->signals = 0L;
  144.  if(info->Swd)      info->signals |= (1L << info->Swd->UserPort->mp_SigBit);
  145.  if(info->Pwd)      info->signals |= (1L << info->Pwd->UserPort->mp_SigBit);
  146.  if(info->appPort)  info->signals |= (1L << info->appPort->mp_SigBit);
  147.  if(info->rexxPort) info->signals |= (1L << info->rexxPort->mp_SigBit);
  148.  if(info->prtPort)  info->signals |= (1L << info->prtPort->mp_SigBit);
  149. }
  150.  
  151. long HandleMsgs(struct prf_info *info)
  152. {
  153.  long rc = CMD_NEUTRAL;
  154.  if(info->Swd)
  155.  {
  156.   while(info->imsg = GT_GetIMsg(info->Swd->UserPort))
  157.   {
  158.    long rc1;
  159.    if((rc1 = HandleImsg(info)) != CMD_NEUTRAL)rc = rc1;
  160.    GT_ReplyIMsg(info->imsg);
  161.   }
  162.  }
  163.  if(info->Pwd)
  164.  {
  165.   while(info->imsg = GT_GetIMsg(info->Pwd->UserPort))
  166.   {
  167.    long rc1;
  168.    if((rc1 = HandleImsg(info)) != CMD_NEUTRAL)rc = rc1;
  169.    GT_ReplyIMsg(info->imsg);
  170.   }
  171.  }
  172.  if(info->appPort)
  173.  {
  174.   while(info->amsg = (struct AppMessage *)GetMsg(info->appPort))
  175.   {
  176.    long rc1;
  177.    if((rc1 = HandleAmsg(info)) != CMD_NEUTRAL)rc = rc1;
  178.    ReplyMsg((struct Message *)info->amsg);
  179.   }
  180.  }
  181.  if(info->rexxPort)
  182.  {
  183.   while(info->rmsg = (struct RexxMsg *)GetMsg(info->rexxPort))
  184.   {
  185.    long rc1;
  186.    if((rc1 = HandleRexxMsg(info)) != CMD_NEUTRAL)rc = rc1;
  187.    ReplyMsg((struct Message *)info->rmsg);
  188.   }
  189.  }
  190.  if(info->prtPort)
  191.  {
  192.  
  193.  }
  194.  return (rc);
  195. }
  196.  
  197. void CheckCmdLine(struct prf_info *info,int argc,union wbstart argv)
  198. {
  199.  struct DiskObject *dobj;
  200.  UBYTE *p,buffer[256],**tta;
  201.  ULONG a,b;
  202.  long cmd = CMD_INSERTTAIL;
  203.  int  i;
  204.  if(argc)
  205.  {
  206.   if(argc > 1)
  207.   {
  208.    for(i=1;i<argc;i++)
  209.    {
  210.     switch(argv.args[i][0])
  211.     {
  212.      case  '-': SetSTFlags(info,&argv.args[i][1]);
  213.                 break;
  214.      default  : info->flags |= FLAG_IMMEDIATE;
  215.                 info->Special1 = (APTR)&argv.args[i][0];
  216.                 info->Special2 = (APTR)&cmd;
  217.                 InsertName(info);
  218.                 info->Special1 = NULL;
  219.                 info->Special2 = NULL;
  220.                 break;
  221.     }
  222.    }
  223.   }
  224.  }
  225.  else
  226.  {
  227.   if(dobj = GetDiskObject(argv.msg->sm_ArgList->wa_Name))
  228.   {
  229.    tta = dobj->do_ToolTypes;
  230.    if(p = (UBYTE *)FindToolType(tta,TOOLTYPE_WD))
  231.    {
  232.     i = sscanf(p,"%ld %ld",&a,&b);
  233.     if(i == 2)
  234.     {
  235.      SwdTags[0].ti_Data = a;
  236.      SwdTags[1].ti_Data = b;
  237.     }
  238.     info->flags |= FLAG_OPENWINDOW;
  239.    }
  240.    if(p = (UBYTE *)FindToolType(tta,TOOLTYPE_FLAGS))
  241.    {
  242.     strcpy(buffer,p);
  243.     SetSTFlags(info,buffer);
  244.    }
  245.    if(p = (UBYTE *)FindToolType(tta,TOOLTYPE_HEAD))
  246.    {
  247.     strcpy(info->Headline,p);
  248.    }
  249.    if(p = (UBYTE *)FindToolType(tta,TOOLTYPE_FOOT))
  250.    {
  251.     strcpy(info->Footline,p);
  252.    }
  253.    if(p = (UBYTE *)FindToolType(tta,TOOLTYPE_LMARGIN))
  254.    {
  255.     info->Lmargin = atol(p);
  256.     if(info->Lmargin > info->Rmargin)info->Lmargin = DEFAULT_LMARGIN;
  257.     if((info->Columns = (info->Rmargin - info->Lmargin)) == 0)
  258.      info->Columns = 1;
  259.    }
  260.    if(p = (UBYTE *)FindToolType(tta,TOOLTYPE_RMARGIN))
  261.    {
  262.     info->Rmargin = atol(p);
  263.     if(info->Rmargin < info->Lmargin)info->Rmargin = DEFAULT_RMARGIN;
  264.     if((info->Columns = (info->Rmargin - info->Lmargin)) == 0)
  265.      info->Columns = 1;
  266.    }
  267.    if(p = (UBYTE *)FindToolType(tta,TOOLTYPE_LINES))
  268.    {
  269.     info->Lines = atol(p);
  270.    }
  271.   }
  272.   if(argv.msg->sm_NumArgs > 1)
  273.   {
  274.    info->flags |= FLAG_IMMEDIATE;
  275.    for(i = 1; i < argv.msg->sm_NumArgs;i++)
  276.    {
  277.     NameFromLock(argv.msg->sm_ArgList[i].wa_Lock,buffer,STR_SIZE);
  278.     AddPart(buffer,argv.msg->sm_ArgList[i].wa_Name,STR_SIZE);
  279.     info->Special1 = (APTR)buffer;
  280.     info->Special2 = (APTR)&cmd;
  281.     InsertName(info);
  282.     info->Special1 = NULL;
  283.     info->Special2 = NULL;
  284.    }
  285.   }
  286.  }
  287. }
  288.  
  289. /* ----------------------------------------------------------------- */
  290. void SetSTFlags(struct prf_info *info,UBYTE *buffer)
  291. {
  292.  int i;
  293.  for(i=0;i< strlen(buffer);i++)
  294.  {
  295.   switch(*(buffer+i))
  296.   {
  297.    case CLI_TIME   : info->flags |= FLAG_TIME;
  298.                      break;
  299.    case CLI_FF     : info->flags |= FLAG_FF;
  300.                      break;
  301.    case CLI_FILE   : info->flags |= FLAG_FILE;
  302.                      break;
  303.    case CLI_PAGE   : info->flags |= FLAG_PAGE;
  304.                      break;
  305.    case CLI_LINE   : info->flags |= FLAG_LINE;
  306.                      break;
  307.    case CLI_CRLF   : info->flags |= FLAG_CRLF;
  308.                      break;
  309.    case CLI_DRAFT  : DoCommand(info,CMD_DRAFT);
  310.                      break;
  311.    case CLI_LQ     : DoCommand(info,CMD_LQ);
  312.                      break;
  313.    case CLI_DATE   : info->flags |= FLAG_DATE;
  314.                      break;
  315.    case CLI_WD     : info->flags |= FLAG_OPENWINDOW;
  316.                      break;
  317.    case CLI_10CPI  : DoCommand(info,CMD_10CPI);
  318.                      break;
  319.    case CLI_12CPI  : DoCommand(info,CMD_12CPI);
  320.                      break;
  321.    case CLI_15CPI  : DoCommand(info,CMD_15CPI);
  322.                      break;
  323.    case CLI_PITCH6 : DoCommand(info,CMD_PITCH6);
  324.                      break;
  325.    case CLI_PITCH8 : DoCommand(info,CMD_PITCH8);
  326.                      break;
  327.    default  : break;
  328.   }
  329.  }
  330. }
  331. /* ----------------------------------------------------------------- */
  332. /* ----------------------------------------------------------------- */
  333. /* ----------------------------------------------------------------- */
  334. /* ----------------------------------------------------------------- */
  335. /* ----------------------------------------------------------------- */
  336.  
  337.  
  338.  
  339.